import { request } from '../request';

export function getCouseList() {
  return request<any>({
    url: '/home/',
    method: 'get'
  });
}

/**
 * 根据班级获取作业
 *
 * @param data
 * @returns
 */
export function getHomeworkByCourse(data: { coursename: any }) {
  console.log(data);
  return request<any>({
    url: `/home/${data.coursename}/`,
    method: 'get'
  });
}

/**
 * 为某班级添加作业
 *
 * @param data
 * @returns
 */
export function addHomeworkToCourse(
  coursename: string,
  data: {
    name: string;
    description: string;
    due_date: any;
    allow_ai: boolean;
  }
) {
  return request<any>({
    url: `/home/${coursename}/`,
    method: 'post',
    data
  });
}

/**
 * 修改作业
 *
 * @param coursename
 * @param data
 * @returns
 */
export function updateHomeworkToCourse(
  coursename: string,
  data: {
    name: string;
    description: string;
    due_date: any;
    allow_ai: boolean;
  }
) {
  return request<any>({
    url: `/home/${coursename}/`,
    method: 'put',
    data
  });
}

/**
 * 添加班级
 *
 * @param data
 * @returns
 */
export function addCourse(data: { course_name: string; students_list: string[] }) {
  return request<any>({
    url: '/home/',
    method: 'post',
    data
  });
}

/**
 * 修改班级
 *
 * @param course_name
 * @returns
 */
export function updateCourse(
  course_name: string,
  data: {
    course_name: string;
    students_list: string[];
  }
) {
  return request<any>({
    url: `/home/${course_name}/member/`,
    method: 'put',
    data: {
      course_name: data.course_name,
      students_list: data.students_list
    }
  });
}

export function removeCourse(course_name: string) {
  return request<any>({
    url: `/home/`,
    method: 'delete',
    data: {
      course_name
    }
  });
}

export function getStudentList() {
  return request<any>({
    url: '/home/user/',
    method: 'get'
  });
}

export function getStudentListByCourseName(course_name: string) {
  return request<any>({
    url: `/home/${course_name}/member/`,
    method: 'get'
  });
}
